package top.healthylife.consumer.controller;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import top.healthylife.consumer.domain.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.healthylife.pangwa.client.MyRestTemplate;

import java.util.Map;


/**
 * 服务的调用方
 */

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private MyRestTemplate myRestTemplate;
    @Value("${pangwa.server.host}")
    private String serverHost;
    @Value("${pangwa.server.port}")
    private int serverPort;
    @GetMapping("/goods/{id}")
    public Goods findGoodsById(@PathVariable("id") int id){
         String result = myRestTemplate.pullService("my-provider");
         String url = "http://"+result+"/goods/findOne/"+id;
        //远程调用Goods服务中的findOne接口
        Goods goods = myRestTemplate.getForObject(url, Goods.class);
        return goods;
    }
}
